package tmhprediction.test;

import java.util.HashMap;

import tmhprediction.classification.TMHClassifier;
import tmhprediction.eval.TMHHelixEvaluator;
import tmhprediction.eval.TMHResidueEvaluator;
import tmhprediction.eval.WriteOutput;
import tmhprediction.main.TMHResultMap;

/***
 * Builds a model
 * @author steckl
 *
 */
public class TMHBuildModel {
	
	private static String fileRootDirectory = "unknown";
	
	private static String dirForFirstSVM = fileRootDirectory+"/firstClassifier";
	private static String dirForSecondSVM = fileRootDirectory+"/secondClassifier";
	
	public static void main(String[] args) throws Exception {
		
		String index = "2";
		String testIndex = "0";
		
		String trainingSet = fileRootDirectory+"/impSolSetOut/features_manual_"+index+".arff";
		String testingSet = fileRootDirectory+"/impSolSetOut/features_manual_"+testIndex+".arff";
		String outFolder = dirForFirstSVM;
		
		
		double c = 0.5;
		double g = 0.0078;
		
		doIt(trainingSet,testingSet,outFolder,index,c,g);
	}
	
	static void doIt(String trainingSet, String testingSet, String outFolder, String index, double c, double g) throws Exception
	{
		System.out.println("Start");
		TMHClassifier classifier = new TMHClassifier(trainingSet, testingSet, g,c ,40);
		System.out.println("Running with C:"+classifier.getcost() +" and gamma:"+classifier.getGamma() + ". Train and test are: "+trainingSet+" "+testingSet);

		System.out.println("Training done, now classification and evaluation");
		TMHResultMap resM = classifier.createResultMap();
		
		System.out.println("Calculate per residue scores");
		TMHResidueEvaluator.calcPerResidueScores(resM, outFolder+"/"+index+"_scoresPerRes");
		
		System.out.println("Writing out predictions in human readable format");
		WriteOutput.writeObservedAndPredicted(resM, outFolder+"/"+index+"_readablePrediction");
		
		System.out.println("Calculating and writing out per segment scores");
		TMHHelixEvaluator.berechneFormeln(TMHHelixEvaluator.finalHelixEvaluation(resM), outFolder+"/"+index+"_scoresPerSeg");

		classifier.saveModel(outFolder+"/"+index+"_model.svm");
		System.out.println("Model saved (for realz!)");
		
	}

}
